<template>
  <el-dialog
    title="回退到指定步骤"
    :visible.sync="rebackVisible"
    :show-close="false"
    width="30%"
    center>
    <div>
      <el-select v-model="prevStep" placeholder="请选择" @change="rebackChange">
        <el-option
          v-for="item in allStep"
          :key="item.id"
          :label="item.name"
          :value="item.id">
        </el-option>
      </el-select>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancle">取 消</el-button>
      <el-button type="primary" @click="saveRebackFunc">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { setReback } from '@/api/oa/index.js'
import mixin from '@/mixins/index.js'
export default {
  mixins: [mixin],
  data () {
    return {
      // allStep: [],
      prevStep: '',
      next_user_id: '',
      returnStep: 0
    }
  },
  props: ['approve', 'rebackVisible', 'allStep'],
  methods: {
    setsetRebackDo () {
      if (isNaN(this.returnStep) && this.returnStep !== 0) {
        this.$message.error('请选择回退步骤')
        return false
      }
      const params = {
        openid: window.localStorage.getItem('token'),
        // approve_id: this.approve.approve_id,
        workflow_id: this.approve.workflow_id,
        approve_node_id: this.returnStep
      }
      setReback(params).then(res => {
        this.$message.error('回退成功')
        this.goFrom()
      })
    },
    saveRebackFunc () {
      this.setsetRebackDo()
      this.$emit('rebackChild')
    },
    cancle () {
      this.$emit('rebackChild')
    },
    rebackChange (e) {
      this.returnStep = e
    }
  }
}
</script>
